const pageHelper = require("../../../../../helper/page_helper.js");
const ProjectBiz = require("../../../biz/project_biz.js");
const MeetBiz = require("../../../biz/meet_biz.js");

import { apiGetisit, apiGetisitAdmin } from "../../../../../api/index.js";

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		isLogin: true,
		dataList: [
			{
				id: 1,
				JOIN_STATUS: 1,
				isTimeout: false,
				JOIN_IS_CHECKIN: 1, // 是否核销
				JOIN_MEET_TITLE: "预约名称",
				JOIN_CNT: 2,
				JOIN_NAME_LIST: "张三，李四，王武",
				JOIN_MEET_DAY: "2024年02月20日(周二) 09:00~12:00"
			}
		]
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: async function (options) {
		ProjectBiz.initPage(this);

		const userName = wx.getStorageSync("userName");
		if (userName) {
			this.setData({
				userName
			});
		}

		let res;

		if (userName && userName === "admin") {
			res = await apiGetisitAdmin()
		} else {
			res = await apiGetisit({
				openId:
					userName && userName === "admin" ? null : wx.getStorageSync("openId")
			});
		}



		if (res.code === 200) {
			res.data.forEach((element) => {
				const peopleName = element.persons.map((v) => v.name).join("、");
				element.peopleName = peopleName;
			});

			this.setData({
				dataList: res.data,
				isLoad: true
			});
		}
		// this._getSearchMenu();
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () { },

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () { },

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () { },

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () { },

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () { },

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () { },

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () { },

	url: async function (e) {
		const iteminfo = pageHelper.dataset(e, "detail");
		wx.setStorageSync("itemInfo", iteminfo);
		pageHelper.url(e, this);
	},

	bindCommListCmpt: function (e) {
		// pageHelper.commListListener(this, e);
	},

	/** 搜索菜单设置 */
	_getSearchMenu: function () {
		let sortItem1 = [];

		let sortItems = [];

		let sortMenus = [{ label: "全部", type: "", value: "" }];

		if (MeetBiz.getCateList().length > 1) {
			sortMenus = sortMenus.concat(MeetBiz.getCateList());
		}

		sortMenus = sortMenus.concat([
			{ label: "今日", type: "today", value: "" },
			{ label: "明日", type: "tomorrow", value: "" },
			{ label: "可使用", type: "use", value: "" },
			{ label: "已过期", type: "timeout", value: "" },
			{ label: "系统取消", type: "cancel", value: "" }
		]);

		this.setData({
			search: "",
			sortItems,
			sortMenus,
			isLoad: true
		});
	},
	bindCancelTap: async function (e) {


		// pageHelper.showConfirm("确认取消该预约?", callback);
	}
});
